package com.globagames.isometric.core.business
{
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	import mx.rpc.IResponder;
	
	
	public class FileAccessDelegate
	{
		private static var DELIMITER:String = "\n";
		private var responder : IResponder;		
		
		public function FileAccessDelegate( responder : IResponder )
		{					
			this.responder = responder;
		}
		
		public function loadArrayFile(name:String) : void
		{	
			trace("name="+name);
			var request:URLRequest = new URLRequest(name);
			var loader:URLLoader = new URLLoader();
			loader.addEventListener(Event.COMPLETE, onTextLoaded);	
			loader.load(request);
		}
		public function onTextLoaded(event:Event):void {	
			var loader:URLLoader = URLLoader(event.target);
			var str:String = loader.data as String;
			var tab:Array = str.split(DELIMITER); 
			responder.result(tab);
		}
		public function loadPNGFile(name:String, fromApplicationStorage:Boolean) : void
		{
			var pictLdr:Loader = new Loader();			
		  	pictLdr.contentLoaderInfo.addEventListener(Event.COMPLETE, onPNGImgLoaded);			
		  	pictLdr.load(new URLRequest(name));	
		}
		public function onPNGImgLoaded(event:Event):void {	
			var pictLoad:Bitmap = Bitmap(event.target.content);
			responder.result(pictLoad.bitmapData);
}
		
		

	}
}